<template>
	<view class="">
		<scroll-view class="wrap" scroll-y="true">
			<view class="item">
				<view class="h bold">
					门店名称：{{detail.deptName}}
				</view>
				<view class="grid">
					<image class="grid-item" :src="detail.showImgUrl" mode=""></image>
					<view class="right-item">
						<view class="p">
							房号：{{detail.roomNum}}
						</view>
						<view class="p" style="margin-top: 8rpx;">
							总房租：{{detail.contractPrice}}元
						</view>
						<view class="p" style="margin-top: 8rpx;">
							押金：{{detail.contractDeposit}}元
						</view>
						<view class="p" style="margin-top: 8rpx;">
							共付：{{detail.rentalAmount}}元
						</view>
						<!-- <view class="p">
							付款方式：月付
						</view> -->

					</view>
				</view>
				<!-- <view class="p" style="margin-top: 30rpx;">
					租赁时长：12月
				</view> -->
				<!-- 	<view class="p" style="margin-top: 15rpx;">
					付款方式：月付
				</view> -->
			</view>

			<view class="item">
				<view class="h" style="padding-bottom: 8rpx;">
					合同编号：{{detail.contractId}}
				</view>
				<view class="p">
					租户：<text style="margin-right: 10rpx;" v-if="detail.contract_form==1">{{detail.unitName}}</text>
					<text style="margin-right: 10rpx;" v-if="detail.contract_form==0">{{detail.cardName}}
						{{detail.contractPhone}}</text>
					{{detail.cardName}} {{detail.contractPhone}}
				</view>
				<view class="p">
					付款方式：{{type}}
				</view>
				<view class="p">
					<!-- 租赁时长：{{detail.creactTime}} -->
				</view>
				<!-- <view class="p">
					租赁时长：租赁时长
				</view> -->
				<view class="p" style="border-bottom: 1rpx solid #f3f3f3;padding-bottom: 12rpx;">
					合同日期：{{detail.startTime}} 至 {{detail.endTime}}
				</view>
				<view class="p" style="margin-top: 12rpx;">
					创建时间：{{detail.createTime}}
				</view>
			</view>
			<view class="item">
				<view class="h" style="padding-bottom: 8rpx;">
					支出明细
				</view>
				<view class="p" v-if="num==1">
					本次需支付租金：{{detail.payPrice - detail.contractDeposit}}
				</view>
				<view class="p" v-if="num==1">
					<!-- <view class="p" v-if=""> -->
					押金：{{detail.contractDeposit}}元
				</view>
				<view class="p">
					总计：{{detail.payPrice}}
				</view>
			</view>

			<div class="text">
				<div @tap.stop="checked">
					<div class="radius" v-if="radius == false"></div>
					<img class="radius-checked" src="../../static/benefits.png" v-else></img>
				</div>

				<div>
					查看并同意
					<span class="orange" @tap.stop='lookpdf'>租房合同.pdf</span>

				</div>
			</div>
		</scroll-view>
		<view class="fixed">
			<button
				style="border-radius: 100rpx;background: #fd7700;text-align: center;height: 7vh;line-height: 7vh;width: 55%;color: #f3f3f3;margin: 1.5vh 0 1.5vh 40%;font-size: 30rpx;"
				@click="oder()">立即支付</button>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				radius: false,
				detail: [],
				num: 1,
				type: '',
				pdf: '',
				contractId: '',
				init: 0
			};
		},
		methods: {
			oder() {
				if (this.radius == false) {
					uni.showToast({
						title: '请勾选租房合同',
						icon: 'none',
						duration: 1500,
					});
				} else {
					let data = {
						contractId: this.contractId,
						payPrice: this.detail.payPrice
					}
					this.api.post('hetong/contract/app/newPayPrice', data).then(res => {
						if (res.data.code == 200) {
							uni.showToast({
								title: '支付成功',
								icon: 'none',
								duration: 1500
							});
							if (this.init == 1) {
								// uni.redirectTo({
								// 	url: 'pages/my/contract'
								// });
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/my/contract'
									})
								}, 1000);
							} else {
								setTimeout(() => {
									// uni.$emit('init', {
									// 	init: 1
									// })
									// uni.navigateBack({
									// 	delta: 1
									// })
									uni.navigateBack({
										delta: 1,
										// success: function() {
										// 	const pages = getCurrentPages(); //获取当前页面栈
										// 	const prevPage = pages[pages.length -
										// 		1]; //获取上一个页面实例对象
										// 	prevPage.onLoad(); //调用上一个页面的onLoad方法
										// }
									});
								}, 500);
							}
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 1500
							});
						}
					})
				}
			},

			showToast() {
				uni.showToast({
					title: '该功能暂未开放',
					icon: 'none',
					duration: 1500
				});
			},
			checked() {
				this.radius = !this.radius
			},

			getDetail(data) {
				this.api.get('hetong/contract/app/selNewContract', data).then(res => {
					if (res.data.code == 200) {
						this.detail = res.data.data
						this.contractId = res.data.data.contractId
						this.pdf = res.data.data.cardPdfUrl
						let typeId = res.data.data.contractType
						this.api.get('system/dict/data/list?pageNum=1&pageSize=50&dictType=contract_type', '')
							.then(type => {
								if (type.data.code == 200) {
									for (let i = 0; i < type.data.rows.length; i++) {
										if (typeId == type.data.rows[i].dictValue) {
											this.type = type.data.rows[i].dictLabel
										}
									}
								} else {
									uni.showToast({
										title: type.data.msg,
										icon: 'none',
										duration: 1500
									});
								}
							})
					}
				})
			},

			androidOpenPdf(url) {
				uni.downloadFile({
					url: url,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							success: function(res) {},
						});
					},
				});
			},

			lookpdf() {
				console.log(this.pdf);
				switch (uni.getSystemInfoSync().platform) {
					case "android":
						this.androidOpenPdf(this.pdf);
						break;
					case "ios":
						uni.navigateTo({
							url: "/pages/webView/webView?url=" + this.pdf,
						});
						break;
					default:
						this.androidOpenPdf(this.pdf);
						break;
				}
			},

		},

		onLoad(option) {
			if (option.init == 1) {
				this.init = 1
			}

			if (option.id) {
				this.contractId = option.id
				this.init = 0
				let data = {
					contractId: option.id
				}
				return this.getDetail(data)
			} else {
				let data = {
					openId: uni.getStorageSync('openId')
				}
				return this.getDetail(data)
			}

		},
		onShow() {
			console.log(2);
		},
		onReady() {
			console.log(3);
		},
	};
</script>


<style lang="scss">
	.wrap {
		width: 700rpx;
		height: 90vh;
		padding: 0 25rpx;
		background-color: #f9f9f9;

		.bold {
			font-weight: bold;
		}

		.item {
			width: 90%;
			// height: 100rpx;
			border-radius: 25rpx;
			padding: 30rpx 30rpx 20rpx;
			background-color: #fff;
			margin: 0 auto;
			filter: drop-shadow(4rpx 4rpx 6rpx gray); // 设置图片的阴影
			margin-bottom: 40rpx;
			// background-color: white;

			.h {
				font-size: 30rpx;
			}

			.p {
				font-size: 26rpx;
				padding-top: 8rpx;
			}

			.img {
				width: 300rpx;
				margin-top: 30rpx;
			}

			.grid {
				display: flex;
				margin-bottom: 15rpx;

				.grid-item {
					width: 250rpx;
					height: 200rpx;
					border-radius: 10rpx;
					margin-top: 30rpx;
				}

				.right-item {
					margin-top: 25rpx;
					margin-left: 20rpx;
				}
			}
		}

		.fixed {
			width: 100%;
			height: 10vh;
			background-color: #adadad;
			position: fixed;
			bottom: 0;
		}

		.text {
			// position: fixed;
			// bottom: 14.5vh;
			// left: 155rpx;
			// margin-left: 140rpx;
			margin: 2vh auto 0;
			width: 100%;
			display: flex;
			justify-content: center;
			height: 30rpx;
			line-height: 30rpx;
			font-size: 26rpx;
			color: #9f9f9f;

			.radius {
				width: 22rpx;
				height: 22rpx;
				border-radius: 50%;
				border: 1rpx solid #adadad;
				// background-color: #ef8545;
				margin-right: 15rpx;
				margin-top: 3rpx;
			}

			.radius-checked {
				width: 22rpx;
				height: 22rpx;
				border-radius: 50%;
				border: 1rpx solid #ef8545;
				// background-color: #ef8545;
				margin-top: 3rpx;
				margin-right: 15rpx;
			}

			.orange {
				color: #ef8545;
				margin: 0 5rpx;
			}
		}
	}
</style>